import React, {forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState} from 'react';
import { Button} from 'antd';
import {useHistory , useLocation} from "react-router-dom";

const Child = React.forwardRef(function (props, ref) {

    let [num , setNum] = useState(0)
    const addFn = ()=> {
        setNum(num+1)
    }
    useImperativeHandle(ref , () => {
        return {
            num,
            addFn
        }
    })
    return <div>
        <div style={{'height': '50px'}}>{num}</div>
        <Button onClick={addFn.bind(null)}>新增num1</Button>
    </div>

})
const Dome = function () {
    const location = useLocation()
    console.log(location.state)
    let x = useRef()
    useEffect(()=>{
        console.log(x)
    })
    return <div>
        <Child ref={x} />
    </div>
}
export default Dome
